import java.awt.Color;

public class JavaOverlayBoard extends JavaBoard {
    private static final Color BORDER_COLOR_GREEN   = new Color(0xff94eb24);
    private static final Color BORDER_COLOR_RED     = new Color(0xffeb2424);
    
    private JavaTile mTile;
    private int[] mTileCoordinates;
    
    private boolean mIsValid;

    public JavaOverlayBoard(int[][] map) {
        super(map);
    }
    
    public void moveTile(int direction) {
        if(mTileCoordinates != null) {
            int[] coords = getNeighborCoordinates(mTileCoordinates, direction);
            placeTile(coords, mTile);
        }
    }
    
    public void clear() {
        if(mTileCoordinates != null) {
            put(mTileCoordinates, null);
        }
        
        mTileCoordinates = null;
        mTile = null;
        
        notifyChanged();
    }
    
    public boolean placeTile(int[] coordinates, JavaTile tile) {
        if(super.placeTile(coordinates, tile)) {
            if(mTileCoordinates != null) {
                put(mTileCoordinates, null);
            }

            mTile = tile;
            mTileCoordinates = coordinates;
//            setCell(tile, coords);
            return true;
        }
        
        return false;
    }
    
    public JavaTile getTile() {
        return mTile;
    }
    
    public int[] getTileCoordinates() {
        return mTileCoordinates;
    }
    
    public void setValid(boolean valid) {
        mIsValid = valid;
    }
    
    public Color getBorderColor() {
        return mIsValid ? BORDER_COLOR_GREEN : BORDER_COLOR_RED;
    }
}
